<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象创建Class版</title>
</head>
<body>
    <script>
         //第四种 Class ：语法糖，实质是构造函数的实现方式
         //原型 （prototype）任何对象都有原型，原型套原型称之为原型链
        class Book{
            constructor(id,name,price){
                this.id = id
                this.name = name
                this.price = price
                this.lent()
                console.log("请在规定时间内归还，逾期将赔款" + this.price + "元")
            }

            sayHello(){
                console.log("你好，同学")
            }

            lent(){
                console.log("编号为" + this.id + "的书本《" + this.name + "》被借走了")
            }
        }
        let b1 = new Book("0001","红楼梦","33")
        b1.sayHello()
        console.log(b1)
        let b2 = new Book("0004","三国演义","45")
        console.log(b2)
        console.log(b1.__proto__ === b2.__proto__)
        // b1.__proto__.time = 9.29  可以调用，但是一般不使用


        //对象常用的方法( Object.xxx() )
        let product = {
            name:"iphone 17" ,
            color:"gray" ,
            price:"$3999" ,
            time:"2025/9/29" ,
            huge:"512GB"
        }
        let keys = Object.keys(product)
        console.log(keys)
        console.log(Object.values(product))
        let entry = Object.entries(product)
        console.log(entry)
        for(let x = 0 ; x < entry.length ; x ++){
            console.log(entry[x])
            for(let i = 0 ; i < entry[x].length ; i++)
            console.log(entry[x][i])
            console.log("===========================")
        }

        console.log("=====================新for循环====================")
        
        for(entry1 of entry){
            console.log(entry1)
            for(item of entry1){
                console.log(item)
            }
            console.log("-----------------------")
        }
    </script>
</body>
</html>